<template>
  <div>
    <a-select
      :value="values"
      optionFilterProp="label"
      show-search
      placeholder=""
      style="width: 90%"
      @change="handerChange"
      :disabled="disabled"
    >
      <a-select-option v-for="item in options" :key="item.value" :value="item.value" :label="item.label">{{
        item.label
      }}</a-select-option>
    </a-select>
    <a-popconfirm placement="bottomLeft" ok-text="确定" cancel-text="取消" @confirm="confirm" :disabled="disabled">
      <template #title>
        <!--          <div class="table-page-search-wrapper">-->
        <!--            <a-form layout="inline" @keyup.enter.native="searchQuery">-->
        <!--              <a-row :gutter="24">-->
        <!--                <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
        <!--                  <a-form-item label="仓库">-->
        <!--                    <j-dict-select-tag placeholder="请选择仓库" v-model="queryParam.wareHouseId" dictCode="erp_warehouse,name,id"/>-->
        <!--                  </a-form-item>-->
        <!--                </a-col>-->
        <!--                <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
        <!--                  <a-form-item label="库位编号">-->
        <!--                    <a-input placeholder="请输入库位编号" v-model="queryParam.code"></a-input>-->
        <!--                  </a-form-item>-->
        <!--                </a-col>-->
        <!--                <template v-if="toggleSearchStatus">-->
        <!--                  <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
        <!--                    <a-form-item label="库位名称">-->
        <!--                      <a-input placeholder="请输入库位名称" v-model="queryParam.name"></a-input>-->
        <!--                    </a-form-item>-->
        <!--                  </a-col>-->
        <!--                  &lt;!&ndash;                  <a-col :xl="6" :lg="7" :md="8" :sm="24">&ndash;&gt;-->
        <!--                  &lt;!&ndash;                    <a-form-item label="状态">&ndash;&gt;-->
        <!--                  &lt;!&ndash;                      <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status"/>&ndash;&gt;-->
        <!--                  &lt;!&ndash;                    </a-form-item>&ndash;&gt;-->
        <!--                  &lt;!&ndash;                  </a-col>&ndash;&gt;-->
        <!--                </template>-->
        <!--                <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
        <!--                            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
        <!--                              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
        <!--                              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
        <!--                              <a @click="handleToggleSearch" style="margin-left: 8px">-->
        <!--                                {{ toggleSearchStatus ? '收起' : '展开' }}-->
        <!--                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
        <!--                              </a>-->
        <!--                            </span>-->
        <!--                </a-col>-->
        <!--              </a-row>-->
        <!--            </a-form>-->
        <!--          </div>-->
        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
            <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
            >项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          </div>
          <a-table
            ref="table"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
          >
          </a-table>
        </div>
      </template>
      <span style="width: 100px; height: auto"> <antd-icon type="search-o" /></span>

      <!--        <a-button>BL</a-button>-->
    </a-popconfirm>
  </div>
</template>

<script>
import Vue from 'vue'
import { AntDesignOutline, DashboardOutline, TwitterOutline, SearchOutline } from '@ant-design/icons'
import AntdIcon from '@ant-design/icons-vue'
AntdIcon.add(AntDesignOutline, DashboardOutline, SearchOutline)
Vue.use(AntdIcon)
import ErpLocationList from '@/views/modules/location/ErpLocationList'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import { getAction } from '@api/manage'
import { ajaxGetDictItems } from '@api/api'
export default {
  name: 'TslSupplier',
  describes: '供应商',
  props: {
    value: {
      type: String,
      required: false,
      default: '',
    },
    disabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    // list: {
    //   type: Array,
    //   required: true
    // },
    // currentStatus: {
    //   type: Number,
    //   default: 0,
    //   required: false
    // }
  },
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ErpLocationList,
  },
  data() {
    return {
      values: this.value,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '编号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
          width: 150,
        },
        {
          title: '联系人',
          align: 'center',
          dataIndex: 'contact',
        },
        {
          title: '电话',
          align: 'center',
          dataIndex: 'telephone',
        },
        {
          title: '邮箱',
          align: 'center',
          dataIndex: 'email',
        },
        {
          title: '传真',
          align: 'center',
          dataIndex: 'fax',
        },
        {
          title: '地址',
          align: 'center',
          dataIndex: 'address',
        },
        {
          title: '开户行',
          align: 'center',
          dataIndex: 'bankName',
        },
        {
          title: '账号',
          align: 'center',
          dataIndex: 'accountNo',
        },
        {
          title: '邮编',
          align: 'center',
          dataIndex: 'zipCode',
        },
      ],
      statusColorMap: {
        启用: 'green',
        停用: 'red',
      },
      url: {
        list: '/base/erpSupplier/list',
        delete: '/base/erpSupplier/delete',
        deleteBatch: '/base/erpSupplier/deleteBatch',
        exportXlsUrl: '/base/erpSupplier/exportXls',
      },
      dictOptions: {},
      superFieldList: [],
      list1: [],
      options: [
        { value: 'jack', label: 'Jack' },
        { value: 'lucy', label: 'Lucy' },
        { value: 'tom', label: 'Tom' },
      ],
    }
  },
  created() {
    this.loadDictData()
  },
  mounted() {
    this.$nextTick(() => {})
  },
  computed: {},
  watch: {
    value(newValue) {
      this.value = newValue
      this.values=newValue
    },
  },
  methods: {
    loadDictData() {
      ajaxGetDictItems('erp_supplier,name,id', null).then((res) => {
        if (res.success) {
          this.options = res.result
        }
      })
    },
    confirm() {
      if (this.selectionRows.length > 0) {
        const val = this.selectedRowKeys[0]
        this.values = val
        this.$emit('input', val)
        this.getLocationInfo(val)
      }
      this.onClearSelected()
    },
    handerChange(value, option) {
      this.values = value
      this.$emit('input', value)
      this.getLocationInfo(value)
    },
    getLocationInfo(value) {
      const param = { id: value }
      getAction('/base/erpSupplier/queryById', param).then((res) => {
        if (res.success) {
          // 向外传递
          this.$emit('handlerOk', {
            result: res.result,
          })
        }
      })
    },
    add() {
      this.showModal()
    },
    showModal() {
      this.visible = true
      this.queryParam = { procurementType: this.procurementType }
      this.loadData()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      // fieldList.push({type:'string',value:'wareHouseId',text:'仓库',dictCode:"erp_warehouse,name,id"})
      fieldList.push({ type: 'string', value: 'code', text: '库位编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '库位名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'erp_status' })
      this.superFieldList = fieldList
    },
    handleCancel() {
      this.close()
    },
    handleOk() {
      this.$emit('handlerOk', this.selectionRows[0])
      this.close()
    },
    close() {
      // this.searchReset(false);
      this.queryParam = {}
      this.selectedRowKeys = []
      this.selectionRows = []
      this.visible = false
    },
  },
}
</script>

<style scoped>
/* 覆盖Dropdown菜单项在悬停时的背景颜色 */
.ant-dropdown-menu-item:hover,
.ant-dropdown-menu-submenu-title:hover {
  background-color: inherit; /* 或者设置为初始背景色 */
}
</style>
